package main

import "fmt"

func main() {
	str := "abc"

	for i := 0; i < len(str); i++ {
		fmt.Printf("str[%d] = %c\n", i, str[i])
	}

	for i, data := range str {
		fmt.Printf("str[%d] = %c\n", i, data)
	}

	rangePointer()
}

func rangePointer() {
	//compile error: cannot range over datas (type *string)
	//d := "aAbBcCdD"
	d := [5]int{1, 2, 3, 4, 5} //range successfully
	//d := []int{1, 2, 3, 4, 5} //compile error: cannot range over datas (type *[]int)
	//d := make(map[string]int) //compile error: cannot range over datas (type *map[string]int)
	datas := &d

	for k, d := range datas {
		fmt.Printf("k_addr:%p, k_value:%v\nd_addr:%p, d_value:%v\n----\n", &k, k, &d, d)
	}
}
